CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

# 应用程序输出路径
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/target/${HT_PLATFORM}/bin)

# libhtmpp.so路径
SET(DEP_LIB_HTMPP_PATH ${PROJECT_SOURCE_DIR}/target/${HT_PLATFORM}/lib)

# mpp库路径
SET(DEP_LIB_MPP_PATH ${PROJECT_SOURCE_DIR}/3rd/${PLATFORM}/${HT_PLATFORM}/mpp/lib/)
SET(DEP_INC_MPP_PATH ${PROJECT_SOURCE_DIR}/3rd/${PLATFORM}/${HT_PLATFORM}/mpp/include/)

# isp库路径
SET(DEP_LIB_ISP_PATH ${PROJECT_SOURCE_DIR}/3rd/${PLATFORM}/${HT_PLATFORM}/isp/lib/)
SET(DEP_INC_RGA_PATH ${PROJECT_SOURCE_DIR}/3rd/${PLATFORM}/${HT_PLATFORM}/isp/include/rga/)

# alsa库路径
SET(DEP_LIB_ALSA_PATH ${PROJECT_SOURCE_DIR}/3rd/${PLATFORM}/${HT_PLATFORM}/alsa/lib/)

# ffmpeg库
SET(DEP_LIB_FFMPEG_PATH ${PROJECT_SOURCE_DIR}/3rd/${PLATFORM}/${HT_PLATFORM}/ffmpeg/lib/)
SET(DEP_INC_FFMPEG_PATH ${PROJECT_SOURCE_DIR}/3rd/${PLATFORM}/${HT_PLATFORM}/ffmpeg/include/)

# mediaReader库
#SET(DEP_LIB_MEDIAREADER_PATH ${PROJECT_SOURCE_DIR}/3rd/media/mediaReader/${HT_PLATFORM}/lib/)
#SET(DEP_INC_MEDIAREADER_PATH ${PROJECT_SOURCE_DIR}/3rd/media/mediaReader/${HT_PLATFORM}/include/)

# rtspCaster库
SET(DEP_LIB_RTSPCASTER_PATH ${PROJECT_SOURCE_DIR}/3rd/media/rtspCaster/${HT_PLATFORM}/lib/)
SET(DEP_INC_RTSPCASTER_PATH ${PROJECT_SOURCE_DIR}/3rd/media/rtspCaster/${HT_PLATFORM}/include/)

# opencv库
SET(DEP_LIB_OPENCV_PATH ${PROJECT_SOURCE_DIR}/3rd/opencv/lib/)
SET(DEP_INC_OPENCV_PATH ${PROJECT_SOURCE_DIR}/3rd/opencv/include/)

# YoloV5头文件
SET(DEP_INC_YOLOV5_PATH ${PROJECT_SOURCE_DIR}/demo/YoloV5/)

include_directories(
	# libhtmpp最终需安装到某个目录，demo程序临时和htmpp共享头文件目录
	${PROJECT_SOURCE_DIR}/inc
	
	# mpp头文件
	${DEP_INC_MPP_PATH}
	
	# ffmpeg头文件
	${DEP_INC_FFMPEG_PATH}
	
	# mediareader头文件
	${DEP_INC_MEDIAREADER_PATH}
	
	# rtstpcaster头文件
	${DEP_INC_RTSPCASTER_PATH}

	# opencv头文件
	${DEP_INC_OPENCV_PATH}

	# rga头文件
	${DEP_INC_RGA_PATH}

	# yolov5头文件
	${DEP_INC_YOLOV5_PATH}

	# demo public
	${PROJECT_SOURCE_DIR}/demo
)

link_directories(
	# rtspcaster库路径
	${DEP_LIB_RTSPCASTER_PATH}
	
	# mediareader库路径
	${DEP_LIB_MEDIAREADER_PATH}

	# mpp库路径
	${DEP_LIB_MPP_PATH}
	${DEP_LIB_ISP_PATH}
	${DEP_LIB_HTMPP_PATH}
	${DEP_LIB_FFMPEG_PATH}
)

AUX_SOURCE_DIRECTORY(. pub_src)

function(build_target src)

FOREACH(list ${ARGV})

string(REGEX MATCHALL "[0-9A-Za-z_]*.cpp" tmp_target ${list})
string(REGEX REPLACE ".cpp" "" target ${tmp_target})

message("------------------------------------")
message(STATUS "--> Building ${HT_PLATFORM} ${list} -> ${target}")
message("------------------------------------")



ENDFOREACH(list)

endfunction()


if(HT_PLATFORM MATCHES "rk3588")
     SET(DEP_LIBS
		${DEP_LIB_FFMPEG_PATH}/libavcodec.so.58
		${DEP_LIB_FFMPEG_PATH}/libavformat.so.58
		${DEP_LIB_FFMPEG_PATH}/libswscale-5.so
		${DEP_LIB_FFMPEG_PATH}/libpostproc-55.so
		${DEP_LIB_FFMPEG_PATH}/libavfilter-7.so
		${DEP_LIB_FFMPEG_PATH}/libavutil-56.so
		${DEP_LIB_FFMPEG_PATH}/libswresample-3.so
		
		${DEP_LIB_MPP_PATH}/libdrm.so.2
		${DEP_LIB_MPP_PATH}/libgraphic_lsf.so
		${DEP_LIB_MPP_PATH}/libmali.so.1
		${DEP_LIB_MPP_PATH}/librga.so.2
		${DEP_LIB_MPP_PATH}/librockchip_mpp.so.1
		
		${DEP_LIB_ALSA_PATH}/libasound.so.2
		rknnrt
		rkaiq
		RtspCaster
		rockit
		${DEP_LIB_OPENCV_PATH}/libopencv_core.so.3.4.20
		${DEP_LIB_OPENCV_PATH}/libopencv_imgcodecs.so.3.4.20
		${DEP_LIB_OPENCV_PATH}/libopencv_imgproc.so.3.4.20
    )

endif()


AUX_SOURCE_DIRECTORY(./YoloV5 pub_src)
AUX_SOURCE_DIRECTORY(./${HT_PLATFORM} pub_src)

add_executable(njte ${pub_src} ${list})
TARGET_LINK_LIBRARIES(njte  m dl pthread htmpp ${DEP_LIBS})